<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class PhotoController extends Controller
{


    /***
     * 上传图片
     * @param Request $request
     * @return array
     */
    public function store(Request $request)
    {
        if ($request->hasFile('image') && $request->image->isValid()) {
            $allow_types = ['image/png', 'image/PNG','image/JPEG','image/jpeg','image/GIF', 'image/gif','image/JPG', 'image/jpg'];
            if (!in_array($request->image->getMimeType(), $allow_types)) {
                return ['status' => 0, 'msg' => '图片类型不正确'];
            }
            if ($request->image->getClientSize() > 1024 * 1024 * 3) {
                return ['status' => 0, 'msg' => '图片不能大于3M'];
            }

            $path = $request->image->store('public/images');
            //绝对路径
            $file_path = storage_path('app/') . $path;
            //上传到本地
//            return ['status' => 1, 'msg' => '/storage' . str_replace('public', '', $path)];
            //上传到七牛
            qiniu_upload($file_path);
            return ['status' => 1, 'msg' => 'http://ow5jvs0fi.bkt.clouddn.com/' . basename($file_path)];
        }
    }

}
